In java, there are some signs that are used as simple codes that make it look simpler and allow us to do less typing.
|| ----> or (Usually used in if statement) EX.
if(x == 0 || x ==1) //This means if x equals to 0 or 1, x equals five.
{ //You cannot do if(x == 0 || 1), because it will cause an error.
x = 5;
}
&& ----> and (usually used in if statement) EX.
if(x > 0 && x < 10); //This means if x is greater than 0 and less than 10, x equals five.
{ //You cannot do if(x > 0 && < 10), it will cause an error.
x = 5;
}
! ----> opposite EX.
private boolean isAlive = true; //Makes a boolean variable called isAlive which is set to true.
...
isAlive = !isAlive; //Now isAlive is set to false because isAlive(true) equals to the
//opposite of isAlive(false).
//another way to think of this is !isAlive is the same as saying is-"Not"-Alive.
< ----> less than
----> greater than
EX.
if(x < 0) //means if x is less than 0, x equals -1.
{
x = -1;
}
<= ----> less than or equal to >= ----> greater than or equal to EX.
if(x <= 0) //Instead of using < with line under it, in java, you use <=.
{
x = -1;
}
= ----> equal to (stored into)
EX.
x = y; // x is equal to y (y is stored into x)
== ----> if equal to (only used in if statements) EX.
if(x == 0) //If x is equal to 0, x is 0.
{
x = 0;
}
De Morgan's law has two forms: one for the negation of an and expression and one for the negation of an or expression.
Example:
!(a && b) is the same as !a || !b
!(a || b) is the same as !a && !b
According to the above equalities, choose the correct answer to the following question.
What is the equiavalent to the following....... : ! (( x <= y) && (y > 5))
a. (x <= y) && (y > 5)
b. (x <= y) || (y > 5)
c. (x >= y) || (y < 5)
d. (x > y) || (y <= 5)
e. (x > y) && (y <= 5)
The ! distributes to the equations and the && so one can immediately eliminate answers A and E. !(x < = y) would change the equation to (x > y) so the only possible answer would then be D.
|| ----> or (Usually used in if statement)
EX.
if(x == 0 || x ==1) //This means if x equals to 0 or 1, x equals five. { //You cannot do if(x == 0 || 1), because it will cause an error. x = 5; }&& ----> and (usually used in if statement)EX.
if(x > 0 && x < 10); //This means if x is greater than 0 and less than 10, x equals five. { //You cannot do if(x > 0 && < 10), it will cause an error. x = 5; }! ----> oppositeEX.
private boolean isAlive = true; //Makes a boolean variable called isAlive which is set to true. ... isAlive = !isAlive; //Now isAlive is set to false because isAlive(true) equals to the //opposite of isAlive(false). //another way to think of this is !isAlive is the same as saying is-"Not"-Alive.< ----> less than- ----> greater than
EX.if(x < 0) //means if x is less than 0, x equals -1. { x = -1; }<= ----> less than or equal to>= ----> greater than or equal to
EX.
if(x <= 0) //Instead of using < with line under it, in java, you use <=. { x = -1; }= ----> equal to (stored into)EX.
== ----> if equal to (only used in if statements)
EX.
if(x == 0) //If x is equal to 0, x is 0. { x = 0; }De Morgan's law has two forms: one for the negation of an and expression and one for the negation of an or expression.Example:
!(a && b) is the same as !a || !b
!(a || b) is the same as !a && !b
According to the above equalities, choose the correct answer to the following question.
What is the equiavalent to the following....... : ! (( x <= y) && (y > 5))
a. (x <= y) && (y > 5)
b. (x <= y) || (y > 5)
c. (x >= y) || (y < 5)
d. (x > y) || (y <= 5)
e. (x > y) && (y <= 5)
The ! distributes to the equations and the && so one can immediately eliminate answers A and E. !(x < = y) would change the equation to (x > y) so the only possible answer would then be D.